package com.cuotoniu.lazybug.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

/**
 * Enter Filter
 * Filter all the request URL
 * Check the user account is exist.
 * If the user account is not exist,forward to the login page.
 * 
 * @author HLJ
 *
 */
@WebFilter(urlPatterns="/*")
public class EnterFilter implements Filter {

	public void destroy() {
	}

	/**
	 * Handle the request URL.
	 * Set the encode:UTF-8
	 * 
	 */
	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)req;	/** turn to HttpServletRequest */
		request.setCharacterEncoding("UTF-8");	/** set encode(UTF-8) */
		resp.setContentType("text/html; charset=UTF-8");
		chain.doFilter(req, resp);			
	}

	public void init(FilterConfig arg0) throws ServletException {
	}

}
